<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Construct a new ZMQContext object</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="class.zmqcontext.html">« ZMQContext</a></li>
      <li style="float: right;"><a href="zmqcontext.getopt.html">ZMQContext::getOpt »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.zmqcontext.html">ZMQContext</a></li>
    <li>Construct a new ZMQContext object</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="zmqcontext.construct" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ZMQContext::__construct</h1>
  <p class="verinfo">(PECL zmq &gt;= 0.5.0)</p><p class="refpurpose"><span class="refname">ZMQContext::__construct</span> &mdash; <span class="dc-title">Construct a new ZMQContext object</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-zmqcontext.construct-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>ZMQContext::__construct</strong></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$io_threads</code><span class="initializer"> = 1</span></span>, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$is_persistent</code><span class="initializer"> = <strong><code>true</code></strong></span></span>)</div>

  <p class="para rdfs-comment">
   Constructs a new ZMQ context. The context is used to initialize sockets. A persistent context is required 
   to initialize persistent sockets. 
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-zmqcontext.construct-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">io_threads</code></dt>

     <dd>

      <p class="para">
       Number of io-threads in the context.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">is_persistent</code></dt>

     <dd>

      <p class="para">
       Whether the context is persistent. Persistent context is stored
       over multiple requests and is a requirement for persistent sockets.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-zmqcontext.construct-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
   Throws <span class="classname"><strong class="classname">ZMQContextException</strong></span> if context initialization fails.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-zmqcontext.construct-examples">
 <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4592">
    <p><strong>示例 #1 A <span class="function"><strong>ZMQContext()</strong></span> example</strong></p>
    <div class="example-contents"><p>
     Construct a new context and allocate request socket from it
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;Allocate&nbsp;a&nbsp;new&nbsp;context&nbsp;*/<br /></span><span style="color: #0000BB">$context&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">ZMQContext</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/*&nbsp;Create&nbsp;a&nbsp;new&nbsp;socket&nbsp;*/<br /></span><span style="color: #0000BB">$socket&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$context</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getSocket</span><span style="color: #007700">(</span><span style="color: #0000BB">ZMQ</span><span style="color: #007700">::</span><span style="color: #0000BB">SOCKET_REQ</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'my&nbsp;sock'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Connect&nbsp;the&nbsp;socket&nbsp;*/<br /></span><span style="color: #0000BB">$socket</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"tcp://example.com:1234"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Send&nbsp;a&nbsp;request&nbsp;*/<br /></span><span style="color: #0000BB">$socket</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">send</span><span style="color: #007700">(</span><span style="color: #DD0000">"Hello&nbsp;there"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Receive&nbsp;back&nbsp;the&nbsp;response&nbsp;*/<br /></span><span style="color: #0000BB">$message&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$socket</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">recv</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


</div></div></div></body></html>